<%--
  Created by IntelliJ IDEA.
  User: wesley.wei
  Date: 2018-06-08
  Time: 13:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title>上传文件</title>
    <%@include file="../common/header.jsp"%>
</head>

<body ontouchstart>

<header class='demos-header'>
    <h1 class="demos-title">上传文件</h1>
</header>

<div class='demos-content-padded'>
    <a href="javascript:;" class="weui-btn weui-btn_primary" onclick="chooseFile()">上传照片</a>

</div>

<%@ include file="../common/footer.jsp"%>
<%@ include file="../common/wxlib.jsp"%>

</body>
<script>


    $.ajax({
        type : "GET",
        async : false,
        url : '${basePath}/config/wx/config',
        dataType : "json",
        data : {
            'url' : location.href.split('#')[0]
        },
        success : function(data) {
            console.log(data);
            wx.config({
                debug : false,
                appId : data.appId,// 必填，公众号的唯一标识
                timestamp : data.timestamp,// 必填，生成签名的时间戳
                nonceStr : data.nonceStr,// 必填，生成签名的随机串
                signature : data.signature,// 必填，签名，见附录1
                jsApiList : [ 'chooseImage', 'uploadImage','previewImage'  ]
            });
            wx.ready(function() {
                wx.checkJsApi({
                    jsApiList : [ 'chooseImage', 'uploadImage','previewImage'  ],
                    success : function(res) {
                        // 以键值对的形式返回，可用的api值true，不可用为false
                        // 如：{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
                        //console.log('wx validate success---------')
                        //console.log(res)
                    }
                });
            });

            wx.error(function (res) {
                //console.log('validate error--------');
                //console.log(res);
            })
        },
        error : function(){
            $.alert('网络异常!');

        }
    });


    function chooseFile(){
        wx.chooseImage({
            count: 1, // 默认9
            sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
            sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
            success: function (res) {
                var localIds = res.localIds; // 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
                console.log(localIds)
            }
        });

    }

</script>
</html>
